package com.ht.module.sys.controller;

import com.ht.config.log.annotation.SysLog;
import com.ht.constant.DicConstant;
import com.ht.module.sys.entity.SysDictItem;
import com.ht.module.sys.service.SysDictItemService;
import com.ht.util.JsonResult;
import com.ht.util.Pager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 字典项表 前端控制器
 * </p>
 *
 * @author Auto-generator
 * @since 2021-05-19
 */
@Tag(name = "字典项表 ")
@RestController
@RequestMapping("/sys-dict-item")
public class SysDictItemController {


    @Autowired
    private SysDictItemService sysDictItemService;


    @Operation(summary = "列表查询")
    @GetMapping("/findList")
    @SysLog(msg = "列表查询字典项")
    public JsonResult findList(SysDictItem en) {
        return JsonResult.success(sysDictItemService.findList(en));
    }


    @Operation(summary = "分页查询")
    @GetMapping("/findPage")
    @SysLog(msg = "分页查询字典项")
    public JsonResult findPage(Pager<SysDictItem> pager, SysDictItem en) {
        return JsonResult.success(sysDictItemService.findPage(pager, en));
    }


    @Operation(summary = "新增")
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('SYS_DICT_ITEM_ADD')")
    @SysLog(msg = "新增字典项", type = DicConstant.OperLogType.ADD)
    public JsonResult add(@RequestBody @Validated SysDictItem sysDictItem) {
        sysDictItemService.add(sysDictItem);
        return JsonResult.success();
    }

    @DeleteMapping("/delete-by-id/{id}")
    @Operation(summary = "删除")
    @PreAuthorize("hasAnyAuthority('SYS_DICT_ITEM_DEL')")
    @SysLog(msg = "删除字典项", type = DicConstant.OperLogType.DEL)
    public JsonResult delete(@PathVariable(value = "id") String id) {
        sysDictItemService.delById(id);
        return JsonResult.success();
    }


    @PutMapping("/update")
    @Operation(summary = "修改")
    @PreAuthorize("hasAnyAuthority('SYS_DICT_ITEM_UPDATE')")
    @SysLog(msg = "修改字典项", type = DicConstant.OperLogType.UPDATE)
    public JsonResult updateById(@RequestBody @Validated SysDictItem sysDictItem) {
        sysDictItemService.edit(sysDictItem);
        return JsonResult.success();
    }

}
